<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改密码</title>
    <meta content="webkit" name="renderer">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
    <link href="../lib/layui-v2.5.6/css/layui.css" media="all" rel="stylesheet">
    <link href="../css/public.css" media="all" rel="stylesheet">
    <style>
        .layui-form-item .layui-input-company {
            width: auto;
            padding-right: 10px;
            line-height: 38px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">旧的密码</label>
                <div class="layui-input-block">
                    <input class="layui-input" lay-reqtext="旧的密码不能为空" lay-verify="required" name="oldPassword"
                           placeholder="请输入旧的密码" type="password" value="">
                    <tip>填写自己账号的旧的密码。</tip>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input class="layui-input" lay-reqtext="新的密码不能为空" lay-verify="required" name="password"
                           placeholder="请输入新的密码" type="password" value="">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input class="layui-input" lay-reqtext="新的密码不能为空" lay-verify="required" name="confirmPassword"
                           placeholder="请输入新的密码" type="password" value="">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-filter="saveBtn" lay-submit>确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script charset="utf-8" src="../lib/layui-v2.5.6/layui.js"></script>
<script charset="utf-8" src="../js/lay-config.js?v=1.0.4"></script>
<script charset="utf-8" src="../js/admin.js"></script>

<script>
    layui.use(['form', 'miniTab'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniTab = layui.miniTab,
            $ = layui.jquery;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            if (data.field.password !== data.field.confirmPassword) {
                layer.msg('两次密码不一致', {icon: 2});
                return false;
            }
            var loadIndex = layer.load(2);

            $.ajax({
                url: '/api/admin/modify-my-password',
                type: 'post',
                contentType: "application/json",
                data: JSON.stringify(data.field),
                dataType: "json",
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 0) {
                        layer.msg(res.msg, {icon: 1}, function () {
                            miniTab.deleteCurrentByIframe();
                        });

                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, error: function (data) {
                    layer.close(loadIndex);
                    layer.msg(data.responseJSON.msg, {icon: 2});
                }
            });
            return false;
        });

    });
</script>
</body>
</html>